<script lang="ts" setup name="SealConfirm">
import { onMounted, ref } from "vue";
import SealButton from "../button/index.vue";

// 点击确认与取消
// 确认：关闭弹出框  实现对应的业务
// 取消: 关闭弹出框

const {
  title = "温馨提示",
  text,
  confirmCallback,
  cancelCallback,
} = defineProps<{
  title?: string;
  text: string;
  confirmCallback: () => void;
  cancelCallback: () => void;
}>();

const flag = ref(false);
onMounted(() => {
  flag.value = true;
});
</script>
<template>
  <Transition name="confirm">
    <div class="seal-confirm" v-if="flag">
      <div class="wrapper">
        <div class="header">
          <h3>{{ title }}</h3>
          <a
            href="JavaScript:;"
            class="iconfont icon-close-new"
            @click="cancelCallback"
          ></a>
        </div>
        <div class="body">
          <i class="iconfont icon-warning"></i>
          <span>{{ text }}</span>
        </div>
        <div class="footer">
          <SealButton size="mini" type="gray" @click="cancelCallback"
            >取消</SealButton
          >
          <SealButton size="mini" type="primary" @click="confirmCallback"
            >确认</SealButton
          >
        </div>
      </div>
    </div>
  </Transition>
</template>

<style scoped lang="less">
.seal-confirm {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 8888;
  background: rgba(0, 0, 0, 0.5);
  .wrapper {
    width: 400px;
    background: #fff;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    .header,
    .footer {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
    }
    .body {
      padding: 20px 40px;
      font-size: 16px;
      .icon-warning {
        color: @priceColor;
        margin-right: 3px;
        font-size: 16px;
      }
    }
    .footer {
      text-align: right;
      .seal-button {
        margin-left: 20px;
      }
    }
    .header {
      position: relative;
      h3 {
        font-weight: normal;
        font-size: 18px;
      }
      a {
        position: absolute;
        right: 15px;
        top: 15px;
        font-size: 20px;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #999;
        &:hover {
          color: #666;
        }
      }
    }
  }
}

// 动画进入的类名
.confirm-enter {
  &-from {
    opacity: 0;
  }
  &-active {
    transition: all 0.5s;
  }
  &-to {
    opacity: 1;
  }
}
</style>
